use crate::result;

#[repr(usize)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum XLEN {
    XLEN32 = 1,
    XLEN64 = 2,
    XLEN128 = 3,
}
impl XLEN {
    pub const fn new() -> Self {
        Self::XLEN32
    }

    pub const fn from_usize(val: usize) -> result::Result<Self> {
        match val {
            1 => Ok(Self::XLEN32),
            2 => Ok(Self::XLEN64),
            3 => Ok(Self::XLEN128),
            _ => Err(result::Error::InvalidVariant(val)),
        }
    }

    pub const fn into_usize(self) -> usize {
        self as usize
    }
}
impl Default for XLEN {
    fn default() -> Self {
        Self::new()
    }
}
impl From<XLEN> for usize {
    fn from(val: XLEN) -> Self {
        val.into_usize()
    }
}
impl TryFrom<usize> for XLEN {
    type Error = result::Error;

    fn try_from(val: usize) -> result::Result<Self> {
        Self::from_usize(val)
    }
}
